﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KylinORM.Aspect
{
    /// <summary>
    /// 实体字段特性
    /// </summary>
    [Serializable]
    [AttributeUsage(AttributeTargets.Property)]
    public class EntityFieldAttribute : Attribute
    {
        /// <summary>
        /// 创建EntityFieldAttribute的实例
        /// </summary>
        public EntityFieldAttribute()
        {
        }
        /// <summary>
        /// 设置数据库字段名
        /// </summary>
        /// <param name="fieldName">此属性对应的数据字段名</param>
        public EntityFieldAttribute(string fieldName)
        {
            this.FieldName = fieldName;
        }
        /// <summary>
        /// 设置连接查询数据库字段名
        /// </summary>
        /// <param name="tableName">此属性所属的连接表名</param>
        /// <param name="fieldName">此属性对应的数据字段名</param>
        public EntityFieldAttribute(string tableName, string fieldName)
        {
            this.TableName = tableName;
            this.FieldName = fieldName;
        }
        /// <summary>
        /// 设置查询操作
        /// </summary>
        /// <param name="selectMethod">此字段默认查询操作</param>
        public EntityFieldAttribute(ESelectMethodBase selectMethod)
            : this(selectMethod, null)
        {
        }
        /// <summary>
        /// 设置自定义查询操作
        /// </summary>
        /// <param name="selectMethod">此字段默认查询操作</param>
        /// <param name="selectTemplate">查询模板</param>
        public EntityFieldAttribute(ESelectMethodBase selectMethod, string selectTemplate)
        {
            if (selectMethod == ESelectMethodBase.CustomMethod)
                this.SelectMethod = ESelectMethod.CustomMethod(selectTemplate);
            else
                this.SelectMethod = selectMethod;
        }
        /// <summary>
        /// 数据库表名，使用连接表查询才需要显式指定所属的表名
        /// </summary>
        public string TableName { get; set; }
        /// <summary>
        /// 数据库字段名
        /// </summary>
        public string FieldName { get; set; }
        /// <summary>
        /// 默认查询操作，使用ESelectMethod.CustomMethod()可自定义查询条件
        /// </summary>
        public ESelectMethod SelectMethod { get; set; }
        /// <summary>
        /// 此字段不参与映射
        /// </summary>
        public bool? IsIgnoredField { get; set; }
        /// <summary>
        /// 此字段为主键
        /// </summary>
        public bool? IsPrimaryField { get; set; }
        /// <summary>
        /// 此字段为自增长
        /// </summary>
        public bool? IsIdentityField { get; set; }

    }
}
